# -*- coding: utf-8 -*-
# File : middleware.py
# Author: taoyahui
# Date : 2021/4/10
from django.http import HttpResponseRedirect
from django.utils.deprecation import MiddlewareMixin
from student import redis_utils

#中间件，拦截每次request请求
class Middleware(MiddlewareMixin):

    # 每次接受请求前都会进行处理
    def process_request(self, request):
        print(request.path)

        if request.path != '/login' and request.path != '/logout' and request.path !='/findByToken':
            token = request.COOKIES['token']
            print(token)
            if not redis_utils.get_value(token):
                return HttpResponseRedirect('/user/login/')


